#include "TcpServer.hh"
#include "ThreadQueue.hh"
#include <iostream>
#include <sys/epoll.h>

using std::cout;
using std::endl;
using std::shared_ptr;
using std::function;

// 新连接
void new_connection(const shared_ptr<TcpConnection>& conn){
    cout << conn->To_string();
    cout << " new connection" << endl;
}

// 旧连接
void old_connection(const shared_ptr<TcpConnection>& conn){
    
    string msg = conn->Recv();                     
    cout << msg << endl;
    conn->Send(msg);

}

// 连接关闭 
void close_connection(const shared_ptr<TcpConnection>& conn){
    cout << conn->To_string();
    cout << " close connection" << endl;
}

int main()
{
    ThreadQueue tq(4, 10);
    
    TcpServer tcp_server("127.0.0.1", 8080);
    tcp_server.Set_callback(new_connection, old_connection, close_connection);

    tcp_server.Start();

    tcp_server.Loop();

    return 0;
}